#ifndef MESSAGEMANAGER_H
#define MESSAGEMANAGER_H

#include <QTcpServer>
#include <QTcpSocket>
#include <QMutex>
#include <QMap>
#include <QByteArray>
#include <QThread>
#include <QList>

class MessageReceiver;
class MessageManager : public QTcpServer
{
	Q_OBJECT
	public:
		MessageManager();
		~MessageManager();
		bool Initialize();
		void SendMessage(QHostAddress addr, QByteArray stream);

	protected:
		void incomingConnection(int socketDescriptor);

	private:
		bool DeleteTask(MessageReceiver*);

	private slots:
		void OnSigStreamReceived(QByteArray stream);

	signals:
		void sigNotice(QString str);
		void sigMesasgeReceived(QByteArray stream); //emit signal to mainwindow.ui

	private:
		QMutex _mutex;
		QList<MessageReceiver *> _msgTask;
		QThread *_thread;
		QTcpSocket _socket;
};

#endif // MESSAGEMANAGER_H
